package com.dhcc.core.modules.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.SqlRunner;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.modules.system.entity.JobLog;
import com.dhcc.core.modules.system.service.IJobLogService;

/**
 * 定时任务日志
 * 
 * @ClassName: JobLogController
 * @Description: TODO
 * @author: cyf
 * @date: 2018年1月2日 上午10:19:17
 */
@Controller
@RequestMapping("${sys.backendPath}/joblog")
public class JobLogController extends BaseController {

    private String PREFIX = "/backend/system/job/";

    @Autowired
    private IJobLogService jobLogService;

    /**
     * 跳转到定时任务日志列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "joblog.html";
    }

    /**
     * 获取定时任务日志列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
        Page<JobLog> page = new PageFactory<JobLog>().defaultPage();
        List<JobLog> result = this.jobLogService.list(page, params);
        page.setRecords((List<JobLog>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 删除定时任务日志
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long jobLogId) {
        this.jobLogService.deleteById(jobLogId);
        return R.ok();
    }

    /**
     * 清空定时任务日志
     */
    @RequestMapping(value = "/delete_all")
    @ResponseBody
    public Object deleteAll() {
        SqlRunner.db().delete("delete from sys_job_log");
        return R.ok();
    }
}
